Coding Arduinos and robot building

Ok, so I got a cool grant! And I get to buy these: Amazon.com
AND these: Amazon.com

If anyone has any great ideas about how to use an RFID card, or any cool builds witht he Arduino kit, I’m all ears! THe class is for 8 to 12-year-olds. Ought to be fun!

That’s a nice variety for intro to robotics!

I’ll ask around the Media Lab to see if anyone has experience with that specific robot. Otherwise if you want a partner to getting used to breadboards, we can go over that together!

Thank you. I understand breadboards. And luckily, 8 year old boys, since that’s who mostly signed up. :slight_smile:
I could use some help figuring how to add on to a build. For instance, if we do the dual LED chaser Dual LED Chaser Arduino Project for Beginners how could we add the HRSC04 and a buzzer to that and make it a motion-activated alarm?

Oh, yeah, I want to do BIG things with these kids!

1 Like

That’s awesome!

TBH you’re more experienced in arduino circuitry than I am. Let me know if you’d like to meet to work out the bugs in the code, I’d be happy to join in some hard fun. :rock: :partying_face:

Cool! Congrats on your grants! I used to teach physical computing (though will forever and always consider myself a beginner circuit builder and coder) and am happy to help brainstorm.

Adding on pieces is really a simple process–you have to make sure the power in and out of the circuit remains balanced (5V from the Arduino is still enough for this) and that you have a digital I/O for the ultra sonic distance sensor and the buzzer. Here is a good example of a simpler motion activated alarm: https://www.instructables.com/Arduino-Ultrasonic-Sensor-HC-SR04-With-Buzzer/

Try building the alarm first and see what happens if you add on some additional LEDs and series resistors–can you get the code from the LED chaser to work with the code in the buzzer example? What looks familar–how might they work together to form a bigger project?

I also recommend looking into the components if you haven’t used them before–Arduino has a great site for learning (or there are articles like this too!). Happy to connect if it is helpful. Looks like so much fun!

1 Like

I am good at the building circuits part. But combining the codes?

ARGH.

I’m trying to combine the two I’ll put below. I understand what the code means, I get the fact everything has to be exact. I’ve maintained web pages in the past, coded robots. But I cheat! I find good codes and then cut and paste them. I don’t write code. I do know how to go in and change bits of code to speed things up, or change the way things work. So, I really teach the kids how to build, how the things work, and how to find and verify a code that will work for them and then how to make small changes.

But this time, I couldn’t find a code to do what I wanted. So I was going to combine the codes. And I did. Successfully.

And then I didn’t save it!

And now I can’t replicate it. I need it for this Wednesday. This group is…a lot. 10 boys, mostly 8 and 9 years old. A couple just glance at the Fritzing diagram and build on their own. A couple won’t sit down and won’t listen. It’s interesting. This week we’ll straighten things out, I hope. LOL

If you or ada can offer any help, I’d appreciate it!

Here’s the code://---------------------------------------------------------------------
// Program: moving_light_display
//
// Description: Flashes four LEDs connected to Arduino pins 2 to 5
// in various patterns
//
// Date: 4 April 2016 Author: W.A. Smith
// http://startingelectronics.org
//---------------------------------------------------------------------
// change speed of pattern change in milliseconds here
#define SPEED_MS 75

// change LED patterns here
unsigned char led_pattern = {
0x01, 0x02, 0x04, 0x08, 0x04, 0x02, 0x01, 0x00,
0x06, 0x09, 0x06, 0x09, 0x06, 0x09, 0x06, 0x09,
0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a, 0x05, 0x0a
};

void setup() {
// set pin 2 to 5 as outputs
for (int i = 2; i <= 5; i++) {
pinMode(i, OUTPUT);
}
}

void loop() {
DisplayPattern(led_pattern, sizeof(led_pattern));
delay(SPEED_MS);
}

void DisplayPattern(unsigned char *pattern, int num_patterns)
{
static int pattern_num = 0; // keeps count of patterns
unsigned char mask = 1; // for testing each bit in pattern

// do for LEDs on pin 2 to pin 5
for (int i = 2; i <= 5; i++) {
// check if bit in pattern is set or not and switch LED accordingly
if (pattern[pattern_num] & mask) {
digitalWrite(i, HIGH);
}
else {
digitalWrite(i, LOW);
}
mask <<= 1; // adjust mask for checking next bit in pattern
}
pattern_num++; // move to next pattern for next function call
// keep pattern within limits of pattern array
if (pattern_num >= num_patterns) {
pattern_num = 0;
}
}

And:
// defines pins numbers

const int trigPin = 9;

const int echoPin = 10;

const int buzzer = 11;

const int ledPin = 13;

// defines variables

long duration;

int distance;

int safetyDistance;

void setup() {

pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

pinMode(echoPin, INPUT); // Sets the echoPin as an Input

pinMode(buzzer, OUTPUT);

pinMode(ledPin, OUTPUT);

Serial.begin(9600); // Starts the serial communication

}

void loop() {

// Clears the trigPin

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance= duration*0.034/2;

safetyDistance = distance;

if (safetyDistance <= 5){

digitalWrite(buzzer, HIGH);

digitalWrite(ledPin, HIGH);

}

else{

digitalWrite(buzzer, LOW);

digitalWrite(ledPin, LOW);

}

// Prints the distance on the Serial Monitor

Serial.print("Distance: ");

Serial.println(distance);

}

I put all my coding problems above!

Hi @Jean_Daley So sorry I missed the timeline for this.
Do you still need help with the code?

@Jean_Daley I also missed the timeline for this as well. Just getting back into the PLIX forum. I’ll certainly take a look at this code still though and see if I can help troubleshoot. I know sometimes it can be hard when the hardware/software are not collaborating. I hope you and the young ones still built something cool!

The first thing that I see if there is two void loop () { } bracket sections. Generally, the IDE will only be able to run one for a coding project. If you want them to remain in two separate functions, you could rename one and make sure it is called in the main void loop () { } section. We will also want the LED_pattern to be the output that is triggered by the ultrasonic distance sensor. I hope this helps!

1 Like

Thanks. I gave up on this and went with something I could find a Fritzing diagram for. Robot and Coding Camp ended yesterday. 10 kids learned about Arduinos, code, and built their own robots. It was great!

1 Like