Loops and Arrays of LEDs

AvWqbaURr0GilqBWAi4CGyuVGnWkS30Zmfd0H-caykCq

 

int ledPins[] = { 3, 5, 6, 9, 10 };
int pinCount = 5;
int ledFade[5];
int i;
int prevTime;
int interval = 700;
int fadeSpeed = 5;
int prevFadeTime;
void setup() {
/*
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
*/
Serial.begin(9600);
Serial.println();
Serial.println(“Begin”);
}

void loop() {

int currentTime = millis();
if (currentTime – prevTime >= interval) {
ledFade[i] = 255;
i++;
if (i == 5) {
i = 0;
}
prevTime = currentTime;
Serial.println(currentTime);
for (int n = 0; n < pinCount; n++) {
Serial.print(n + 1);
Serial.print(“\t”);
Serial.println(ledFade[n]);
}
}

if (currentTime – prevFadeTime >= fadeSpeed) {
for (int n = 0; n < pinCount; n++) {
if (ledFade[n] >= 1) {
ledFade[n] = ledFade[n]-1;
}
}
prevFadeTime = currentTime;
}

// display section:
for (int n = 0; n < pinCount; n++) {
analogWrite(ledPins[n], ledFade[n]);
}

}

Arduino LED Meter

AtvcxmGc-AmqTHf5qSg-Ob4YH4RrIbK3KAJ8b8eFBim3

 

int ledPin1 = 10;
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 9;
int ledPin5 = 13;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
}

void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// The analog pin reads from 0 to 1023.
// This commands maps those numbers from 4 to 0
// So 0 becomes 4 and 1023 becomes 0
int mappedSensorValue = map( sensorValue, 0, 1023, 7, 0);
//Here we test the mappedsensorvalue. If it is greater then 1 we turn
// on the LED on Pin 2 and then see if it is greater then 2.

if (mappedSensorValue > 1 ) {
digitalWrite (ledPin5, HIGH);
if (mappedSensorValue > 2) {
digitalWrite (ledPin4, HIGH);
if (mappedSensorValue > 3) {
digitalWrite ( ledPin3, HIGH);
if (mappedSensorValue > 4) {
digitalWrite ( ledPin2, HIGH);
if (mappedSensorValue > 5) {
digitalWrite ( ledPin1, HIGH);
} else { //If it is not greater we start turning LEDs off.
digitalWrite ( ledPin1, LOW);
}
} else {
digitalWrite ( ledPin2, LOW);
}
} else {
digitalWrite ( ledPin3, LOW);
}

} else {
digitalWrite ( ledPin4, LOW);
}

} else {
digitalWrite ( ledPin5, LOW);
}
}

Arduino Night Lights + Melody


#include “pitches.h”
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
pinMode(3, OUTPUT);

int speakerOut = 9;

int DEBUG = 1;
pinMode(speakerOut, OUTPUT);
if (DEBUG) {
Serial.begin(9600); //
}
}
int melody[] = { NOTE_C7, NOTE_GS7,NOTE_C7,NOTE_GS6, NOTE_F7,NOTE_G4, NOTE_GS6, NOTE_GS7, NOTE_F7,NOTE_GS6, NOTE_GS7, NOTE_F7, NOTE_GS7 };
int beats[] = { 16, 16, 16, 8, 8, 16, 32, 16, 16, 16, 8, 8 };
int MAX_COUNT = sizeof(melody) / 6;
long tempo = 20000;

int pause = 1000;

int rest_count = 100;

// Initialize core variables
int tone_ = 0;
int beat = 0;
long duration = 0;

void playTone() {
long elapsed_time = 0;
if (tone_ > 0) { // if this isn’t a Rest beat, while the tone has
// played less long than ‘duration’, pulse speaker HIGH and LOW
while (elapsed_time < duration) {

digitalWrite(9 ,HIGH);
delayMicroseconds(tone_ / 2);

// DOWN
digitalWrite(9 , LOW);
delayMicroseconds(tone_ / 2);

// Keep track of how long we pulsed
elapsed_time += (tone_);
}
}
else { // Rest beat; loop times delay
for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
delayMicroseconds(duration);
}
}
}

void loop() {
// read the sensor:
int sensorValue = analogRead(A0);
Serial.println(sensorValue);

for (int i=0; i<MAX_COUNT; i++) {
tone_ = melody[i];
beat = beats[i];

duration = beat * tempo; // Set up timing

playTone();
// A pause between notes…
delayMicroseconds(pause);

if (sensorValue < 800) { // To change the point at which the light turns on change this value.
digitalWrite(3, LOW);

}
else {
digitalWrite(3,HIGH);
}
}

 
if (sensorValue < 900) {
digitalWrite(3, LOW);

}
else {
digitalWrite(3,HIGH);

}

}

 

 

Arduino Robot

This guide shows you how to quickly and easily build an Arduino-based robot. Robotics is an exciting and fun hobby that has become very affordable in recent years. What would have required a lot of money and experience to do a few decades ago is now affordable, easy, and most of all, FUN!

Simple Arduino Robot

dsc_3028_brightened-medium1

The parts used in this guide can all be purchased together in the Funduino UNO Robotics Kit, but you can follow along with a different kit just as easily as long as you have similar components.

Keep in mind that this tutorial shows just one way to make a robot — you’re limited only by your budget and imagination. If you want to buy more sensors, or a nicer chassis, go for it! The entire process may take an hour or two, so get ready to have some fun!

 

http://makezine.com/projects/building-a-simple-arduino-robot/

Arduino Project by Dheera Venkatraman

 

 

MIT student Dheera Venkatraman has developed a new way for users to wirelessly unlock their doors with simple Google Now-like commands.

The Maker created an app — which is aptly dubbed “Sesame” — via Google Now that lets those adorning an Android Wear watch on their wrist to utter the words “OK Google, Open Sesame” to open a door. That is, of course, after the door is rigged with some “simple yet trivial” hardware.

 

To bring this idea to life, Venkatramann modded his door with an Arduino Uno (ATmega328), a Bluetooth module and a servo, which allows the lock to be activated via its accompanying app. The servo is attached to the door latch, while the Bluetooth module awaits a trigger signal and communicates with the Arduino over serial. Once the process is complete, the Arduino activates the servo to open the door.

 

 

0

 

Android Wear app lets you unlock doors by actually saying “open sesame”