0% found this document useful (0 votes)
25 views10 pages

Arduinobasic

The document contains instructions and code for 10 exercises using an Arduino board. Exercise 1 involves reading resistor color codes. Exercise 2 calculates a resistor value for an LED circuit. Exercise 3 shows the LED circuit diagram. Exercises 4-10 involve coding projects like making an LED flash, adding a push button or light dependent resistor, and coding a traffic light sequence. The extra exercises provide code and diagrams for a multi-LED/button sequencer project and a traffic light project.

Uploaded by

bigmaxcb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views10 pages

Arduinobasic

The document contains instructions and code for 10 exercises using an Arduino board. Exercise 1 involves reading resistor color codes. Exercise 2 calculates a resistor value for an LED circuit. Exercise 3 shows the LED circuit diagram. Exercises 4-10 involve coding projects like making an LED flash, adding a push button or light dependent resistor, and coding a traffic light sequence. The extra exercises provide code and diagrams for a multi-LED/button sequencer project and a traffic light project.

Uploaded by

bigmaxcb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Exercise 1

1. done
2. 2.2 ohm and 100 ohm
3. 1.Green black black red silver
2. black black brown black brown
3. yellow green black orange red

4. 1K ohms with 5% tolerance

1,1K ohms with 5% tolerance

Exercise 2
To have an operating voltage of 2.2V through the led, the resistor needs to “take”
2.8 V. Combining that with the requirement of 13 mA, the value of the resistor is
(R=U/I, 2.8/0.013)= 215 ohm for practicality reasons using a 220 ohm resistor is
fine. It does leads to a voltage of 2.86 and not the demanded one of 2.8 V.
Otherwise a the single resistor can be replaced by multiples in series to get a
more accurate voltage( 200 ohms+10 ohms+5 ohms)
Exercise 3
The circuit diagram is presented in exercise 2:
Exercise 4: Install the Arduino IDE on your computer

Exercise 5: Make your LED flash


Still same diagram as exercise 2.

Questions: Make your LED flash by using the Arduino Change the following connection:

1 What happens if the delay is very small?

There is less time between flashes

2 What happens if the delays are small and different?


If the delay is smaller like in the example above the time between on and off is decreased, which
causes more flickering. The difference in size( in the example above) that it is longer in the on state
then off state.

Exercise 6: Two flashing LEDs

Source: https://thecustomizewindows.com/2018/07/arduino-blink-two-leds-alternatively/

Exercise 7: Push Switch


Exercise 8: Turn LED on for 5 seconds when switch pushed

Exercise 9: Variable speed blinking LED

Source: https://arduinotogo.com/2017/02/28/chapter-6-potentiometer-circuit-step-by-step/
Exercise 10: Light in the dark

Source: https://create.arduino.cc/projecthub/guruashishchoudhary29/turn-led-on-and-off-through-
ldr-fe5738

Extra exercise 1
Code:

// basic functions

int GREEN = 2;

int YELLOW = 3;

int RED = 4;

void setup()

pinMode(GREEN, OUTPUT);

pinMode(YELLOW, OUTPUT);

pinMode(RED, OUTPUT);

void loop()
{

Serial.begin(9600);

digitalWrite(RED, HIGH);

digitalWrite(YELLOW, LOW);

digitalWrite(GREEN, LOW);

delay(2000);

Serial.print("changed to Green ");

digitalWrite(YELLOW, HIGH);

digitalWrite(RED, LOW);

digitalWrite(GREEN, LOW);

delay(2000);

Serial.print("changed to Red '");

digitalWrite(GREEN, HIGH);

digitalWrite(YELLOW, LOW);

digitalWrite(RED, LOW);

delay(2000);

Serial.print("changed to Yellow ");

}
Circuit(except instead of 330 ohms I used 470 ohm resistors):

https://www.kindpng.com/imgv/TwRbbxo_simple-traffic-light-diagram-hd-png-download/

extra exercise 2
circuit(expect 5 leds/buttons instead of 6):

Source: https://www.learnrobotics.org/blog/arduino-record-push-button-sequence/ (this source is


also used for the code)

Code:

int play_led = 13; //define pin # for play led

int record_led = 11; //define pin # for record led


int button[4] = {2,4,6,8}; //store button pins in an array

int leds[4] = {3,5,7,9}; //store led pins in an array

int arr[10]; //store the sequence in an array of size 10

boolean previous = LOW;

unsigned long time1 = 0;

int debounce = 200;

int index_state = 0;

int state = HIGH;

boolean empty = false;

int record_count = 0;

void setup()

for(int i = 0;i<5 ;i++){

pinMode(button[i],INPUT);

pinMode(leds[i],OUTPUT);

for(int n=0;n<10;n++) arr[n] = 7;//initialization

pinMode(record_led, OUTPUT);

pinMode(play_led, OUTPUT);

empty=true;

Serial.begin(9600);

void playback(){

digitalWrite(play_led,HIGH); //turn green led ON

digitalWrite(record_led,LOW); //turn red led OFF

for(int i = 0; i<10; i++){ //set the appropriate LED HIGH then LOW according to sequence array

if (arr[i]!=7){
digitalWrite(leds[arr[i]],HIGH);

delay(250);

digitalWrite(leds[arr[i]],LOW);

delay(250);

digitalWrite(play_led,LOW);

for(int n=0;n<10;n++) arr[n] = 7; //clear array for next time

int arr[10] = {1,0,3,2,2,0,2,1,3,0}; //initialize arr[]

void loop(){

playback();

You might also like