Arduino developed and designed breathing lamp experiments


1. Be familiar with PWM control and programming principle;2. Master the analog I/O interface features and functions;3. Master the function of mapping function;2. Experimental equipment and environment Arduino UNO suite, Arduino IDE, computer, potentiometer, LED lamp, resistor, Dupont wire, etc. 3. Experimental key 1.2. Control program code writing;5. Experimental Content 5.1 Experimental Task Task Description: Read and output potentiometer analog signal value;Potentiometer LED brightness control (PWM);Breathing lamp production.5.2 Experimental principle 1.PWM control PWM is the time to maintain high level within the signal cycle. It is a technology of pulse width debugging based on duty cycle and is used to encode information as pulse signals.The PWM signal frequency of Arduino UNO is F =490Hz, and the output ports are 3, 5, 6, 9, 10, 11, marked as “~”.2. Potentiometer (equivalent to the sliding rheostat in physical appliances) potentiometer is a resistance component with three leads, and the resistance value can be adjusted according to a certain change law.A potentiometer usually consists of a resistance body and a removable brush.When the brush moves along the resistance, the resistance value or voltage is obtained at the output which is related to the displacement.The potentiometer can be used as a three-terminal element or a two-terminal element.The latter can be regarded as a variable resistor, because its role in the circuit is to obtain and input voltage (applied voltage) into a certain relationship with the output voltage, so called potentiometer.The output voltage can be controlled from 0 to Vcc through the sliding port of the potentiometer. If the output value is the maximum gradient brightness of the breathing lamp, the frequency of the breathing lamp on and off can be controlled through the change of the output value.3. Breathing lamp circuit principle diagram: ⑶ Breathing lamp principle when people breathe, by expanding the chest cavity, compression of the chest cavity for inhalation, exhalation to achieve breathing function, continuous inhalation, exhalation to form a regular breathing function.By controlling the brightness of the lamp, the breathing lamp gradually changes from dark to the brightest, and then gradually changes to the darkest. It is repeated constantly, resembling human breathing, and is called the breathing lamp.1. Output circuit diagram of potentiometer analog signal value: Schematic diagram: flow chart: const int light_Pin = A0;void setup() {Serial.begin(9600);int light_Value;}void loop() {light_Value = analogRead(light_Pin);Serial. Print (” light_Value = : “);Serial.println(light_Value); Serial.println(light_Value,BIN);Serial. Println (light_Value,HEX);// Hex output photoresistor read data delay(500);} const int light_Pin = A0;const int ledPin = 5;void setup() { Serial.begin(9600); } void loop() { int light_Value; light_Value = analogRead(light_Pin); Serial.print(“ight_Value =:”); Serial.println(light_Value); Light_Value = map (light_Value, 0102 3,0,255);analogWrite(ledPin,light_Value); delay(100);} code test: extended test: change the above circuit and source program, with R, G, B three color LED to achieve a color changing dazzling light effect, requirements: ⑴ R\G\B monochrome gradient;⑵ R\G\B two-color gradient;⑶ R\G\B tri-color gradient;(4) R\G\B color changes randomly.Const int led_red = 11;const int led_gr5een =10 ;const int led_blue = 9;void setup() { pinMode(led_red, OUTPUT); // Set the OUTPUT mode to pinMode(led_green, OUTPUT);pinMode(led_blue, OUTPUT); analogWrite(led_red, 255); // analogWrite(led_green, 255);// analogWrite(led_blue, 255);} void loop() { for (int i = 0; i <255;i += 5) { analogWrite(led_red, i); analogWrite(led_green, 255); analogWrite(led_blue, 255); delay(100); } for (int i = 255; i > 0;i -= 5) { analogWrite(led_red, i); analogWrite(led_green, 255); analogWrite(led_blue, 255); delay(50); } for (int i = 0; i <255;i += 5) { analogWrite(led_red, 255); analogWrite(led_green, i); analogWrite(led_blue, 255); delay(50); } for (int i = 255; i > 0;i -= 5) { analogWrite(led_red, 255); analogWrite(led_green, i); analogWrite(led_blue, 255); delay(50); } for (int i = 0; i <255;i += 5) { analogWrite(led_red, 255); analogWrite(led_green, 255); analogWrite(led_blue, i); delay(50); } for (int i = 255; i > 0;i -= 5) { analogWrite(led_red, 255); analogWrite(led_green, 255); analogWrite(led_blue, i); delay(50); Const int led_red = 11; const int led_red = 11;const int led_green =10 ;const int led_blue = 9;void setup() { pinMode(led_red, OUTPUT); // Set the OUTPUT mode to pinMode(led_green, OUTPUT);pinMode(led_blue, OUTPUT); analogWrite(led_red, 255); // analogWrite(led_green, 255);// analogWrite(led_blue, 255);} void loop() { for (int i = 0; i <255;i += 5) { analogWrite(led_red, i); / / yellow analogWrite (led_green, I);analogWrite(led_blue, 255); delay(100); } for (int i = 255; i > 0;i -= 5) { analogWrite(led_red, i); / / purple analogWrite (led_green, 255);analogWrite(led_blue, i); delay(50); } for (int i = 0; i <255;i += 5) { analogWrite(led_red, 255); analogWrite(led_green, i); / / green analogWrite (led_blue, I);delay(50); } for (int i = 255; i > 0;i -= 5) { analogWrite(led_red, i); analogWrite(led_green, i); analogWrite(led_blue, 255); delay(50); } for (int i = 0; i <255;i += 5) { analogWrite(led_red, i); analogWrite(led_green, 255); analogWrite(led_blue, i); delay(50); } for (int i = 255; i > 0;i -= 5) { analogWrite(led_red, 255); analogWrite(led_green, i); analogWrite(led_blue, i); delay(50); Const int led_red = 11;const int led_green = 10 ;const int led_blue = 9;void setup() { pinMode(led_red, OUTPUT); // Set the OUTPUT mode to pinMode(led_green, OUTPUT);pinMode(led_blue, OUTPUT); analogWrite(led_red, 255); // analogWrite(led_green, 255);// analogWrite(led_blue, 255);} void loop() { for (int i = 0; i < 255;i ++) { analogWrite(led_red, i); delay(20); if(i=100){ for (int j = 0; j < 255;j++) { analogWrite(led_green, j); delay(20); } } if(i=200){ for (int k = 0; k < 255;k++) { analogWrite(led_blue, k ); delay(20); }}}} Experimental phenomenon:

Leave a Reply

Your email address will not be published.