Young makers from primary school make a basic project with Arduino, leds and Lego, useful to learn basics of programming

Four leds, red, green, yellow and white, connected with Arduino, in a Lego box (make with fantasy)

Leds turn on/off depending to command send to Arduino via console "rosso" turn on red led etc. etc We created also personalized colours, like the color named "Tessi" Tessi command turn on all the lights

// This is the code for Arduino IDE // the original code is based on sunfounder // We add another led (white), translate colors in italian and added the new color "tessi"

const int greenPin= 2; //the green led pin attact to const int yellowPin= 3; //the yellow led pin attact to const int redPin= 4; //the red led pin attach to const int whitePin= 5; //the white led pin attach to String comdata = ""; int lastLength = 0;

void setup() { pinMode(greenPin,OUTPUT); //initialize the greenPin as output pinMode(yellowPin, OUTPUT); //initialize the yellowPin as output pinMode(redPin, OUTPUT); //initialize the redPin as output pinMode(whitePin, OUTPUT); //initialize the whitePin as output Serial.begin(9600); // start serial port at 9600 bps: Serial.print("Quale luce devo accendere ?"); //print message on serial monitor }

void loop() { //read string from serial monitor if(Serial.available()>0) // if we get a valid byte, read analog ins: {
comdata = ""; while (Serial.available() > 0)
{
comdata += char(Serial.read()); delay(2); } Serial.println(comdata); } if(comdata == "rosso") { digitalWrite(redPin, HIGH);//turn the red led on digitalWrite(greenPin, LOW);//turn the green led off digitalWrite(yellowPin, LOW);//turn the yellow led off digitalWrite(whitePin, LOW);//turn the white led off } else if(comdata == "giallo") { digitalWrite(redPin, LOW);//turn the red led off digitalWrite(greenPin, LOW);//turn the green led off digitalWrite(yellowPin, HIGH);//turn the yellow led on digitalWrite(whitePin, LOW);//turn the white led off

}
else if(comdata == "verde")
{
  digitalWrite(redPin, LOW);//turn the red led off
  digitalWrite(greenPin, HIGH);//turn the green led on
  digitalWrite(yellowPin, LOW);//turn the yellow led off
  digitalWrite(whitePin, LOW);//turn the white led off

}
else if(comdata == "bianco")
{
  digitalWrite(redPin, LOW);//turn the red led off
  digitalWrite(greenPin, LOW);//turn the green led on
  digitalWrite(yellowPin, LOW);//turn the yellow led off
  digitalWrite(whitePin, HIGH);//turn the white led off

}
else if(comdata == "tessi")
{
  digitalWrite(redPin, HIGH);//turn the red led off
  digitalWrite(greenPin, HIGH);//turn the green led off
  digitalWrite(yellowPin, HIGH);//turn the yellow led on
  digitalWrite(whitePin, HIGH);//turn the white led on
}

else
{
  digitalWrite(redPin, LOW);//turn the red led off
  digitalWrite(greenPin, LOW);//turn the green led off
  digitalWrite(yellowPin, LOW);//turn the yellow led off
  digitalWrite(whitePin, LOW);//turn the white led off
}    

}

Share this project:

Updates