Designing a basic RGB LED blinking circuit - arduino

The circuit:
Trying to get this just to blink, but can't figure out how.
void setup() {
pinMode(3, OUTPUT);
}
void loop() {
digitalWrite(3, HIGH);
delay(250);
digitalWrite(3 , LOW);
delay(250);
}
Pretty much the stock Arduino code, but I don't know why it won't work with multiple LEDs.
EDIT: The LEDs aren't blown out, because they all still work one at a time.

The problem isn't in your code.
A single standard red LED drops about 1.8 V, and with the proper resistor an Arduino pin can drive such a LED at the right current.
Three LEDs (especially with a blue one among them) in series need more voltage than the Arduino pin can deliver (5 V), so they won't light up. Maybe two LEDs with a recalculated resistor will just about work.
Try leaving out the blue LED; it has the highest voltage drop (about 3 to 3.3 V), so adding one other LED will already go too close to, or beyond, 5 V, and the LEDs won't light up.
You could put the LEDs in parallel, each with their own properly calculated resistor, but the total current you pull in that configuration may exceed the maximum current allowed per Arduino pin (this depends on the Arduino used: about 20 mA for most Arduinos, but only 7 mA for SAMD21-based Arduinos).

Related

I set my pushbutton switch up incorrectly

I am fiddling with an Arduino Uno and trying to get two switches to operate two servo motors. I am not able to do this right now, and I am not sure what my issue is. I know that my servos are wired correctly; however, I highly doubt that my switches are correctly wired.
Here is a diagram of my circuit and the code that I am using.
#include <Servo.h>
Servo servo_11;
Servo servo_10;
void setup()
{
servo_11.attach(11);
servo_10.attach(10);
pinMode(A3, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A2, INPUT);
}
void loop()
{
servo_11.write(0);
servo_10.write(0);
digitalWrite(A3, LOW);
digitalWrite(A2, LOW);
if (analogRead(A2) != LOW) {
servo_11.write(180);
}
delay(10);
}
Circuit image
If anyone could point out what's wrong, I would really appreciate it!!
You have floating inputs. When the button isn't pressed the pin isn't connected to anything. So the pin can read whatever noise it happens to pick up from the environment. You need pull-down or pull-up resistors. If you use pull-ups, then you can use the ones built into the chip.
You also seem to be confusing analogRead and digitalRead. It's digitalRead that gets HIGH and LOW. analogRead gets values from 0 to 1023 for 0 to 5V.
pull-down resistor circuit
try looking on this to understand the concept
it makes sure that when you dont press the pin will read ground and only when it presses the button you make voltage divider that ups the volage to a non-zero to give you HIGH

Arduino: Using analogRead() on Photoresistor to read LED with PWM

I have been working on a project with Arduino and have come across something that I find fascinating/confusing. So, I had to test something before constructing this project. I built a simple circuit that consists of just an LED and photoresistor. What I had to test was whether the photoresistor was capable of determining the brightness of an LED that was being dimmed through PWM. My initial expectation was that this would not work (the photoresistor would either read 1023 or 0 because PWM is achieved digitally). To my surprise, the photoresistor was able to accurately read the brightness of the LED (accurately to an extent -- this is simply based off of comparing the apparent brightness of the PWM LED with an LED placed in series with a certain resistor)! This is exactly what I wanted, but I am just curious as to why this works. I am not sure if my original doubt was due to a misunderstanding of photoresistors or PWM. Any help would be much appreciated. Thank you!
Here is the code I am running (I am not using the analogWrite() function because the project I am working on requires me to have a certain level of control over the PWM):
const int LED_PIN = 9;
const int PHOTO_PIN = 0;
//These values have been altered and tested
const int HIGH_TIME = 250;
const int LOW_TIME = 2750;
void setup()
{
pinMode(LED_PIN, OUTPUT);
pinMode(PHOTO_PIN, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(LED_PIN, HIGH);
delayMicroseconds(HIGH_TIME);
digitalWrite(LED_PIN, LOW);
delayMicroseconds(LOW_TIME);
Serial.println(analogRead(PHOTO_PIN));
}
A "photoresistor" is a variable resistor. That is the simplest way to say it.
Just imagine your potentiometer, you can control its resistance by turning the little knob and then analogRead it. The photoresistor on the other side, changes it resistance depending on the light intensity. Because of that, the resistance will go up and down depending on your LED.
For "HOW" it actually works, see here.
Now, there are a couple of factors to consider:
1 - The ambient light of your room.
2 - The distance between your LED
So hope I helped you learn a little more about photoresistors!
The response time of the photo resistor is much slower than the PWM frequencies you are using. So it averages the on and off times of the LED and gives a resistance proportional to the average light. If you were using a photodiode with a fast response time, it would be able to "see" the LED go on and off.
I suggest that you don't try to write to the Serial port every time through the loop since it will quickly fall behind at 9600 baud. Perhaps write every 500 times through the loop.

Arduino UNO + Ethernet Shield + Ultrasonic Sensor = Fail

With my Arduino Uno I measure the distance using HC-SR04 ultrasonic sensor with no problems at all using the wiring below.
When I attach ethernet shield, my ultrasonic sensor does not measure distance any more, it constantly says 0cm no matter what. I have tried different digital pin pairs such as 5-7, 6-8, 5-9, 3-5, 2-8 but no luck.
I suspect that HC-SR04 is not compatible with my Ethernet shield but I haven't seen such warning anywhere on the net.
There are no components attached to arduino besides ethernet shield and the ultrasonic sensor itself.
There is no SD Card in SD Card slot.
My ethernet shield works fine while running a web server or web client script.
Digital pins of ethernet shield works fine with all other components such as temperature sensor, motion sensor etc.
Here is the ethernet shield I have;
http://www.ezshopfun.com/product_info.php?products_id=169
Here is my actual circuit;
http://s7.postimg.org/vyi2z36qz/20140826_001130.jpg
http://s7.postimg.org/6eb7ewvzf/20140826_001150.jpg
http://s7.postimg.org/6psnrocff/20140826_001156.jpg
http://s7.postimg.org/y6ro2ooh7/20140826_001229.jpg
http://s7.postimg.org/71a44fsvf/20140826_001247.jpg
Here is my code;
#define trigPin 6
#define echoPin 7
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH) / 2;
distance = duration / 29.1;
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
Today I bought a multimeter and tested my circuit. Here are the results;
When my circuit directly attached to Arduino itself;
4.80V & 5.7mA
When my circuit attached to ethernet shield;
3.06V & 3.8mA
I think the problem is that 3.06V is not enough for my HC-SR04 to operate.
Yeah based on this photo
you're not grounding your sensor. You have two power supplies going into it. This, needless to say, is bad for a number of reasons. First and foremost because it wont work ungrounded lol
As others have said, it looks like the main issue is that you need this connected to 5V and check your wiring generally.
However, there is another potential issue:
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
You only need to set the trigger pin high for 10 microseconds, not 1000 microseconds. I don't know if this is an issue or not but there is no need to wait this long. You could potentially be missing some or all of the incoming pulse by waiting that long.
You might want to checkout out some HC-SR04 tutorials too, like this one:
http://superawesomerobots.com/tutorials/hc-sr04-tutorial-for-arduino/
Hope that helps.
I had a similar problem with a wifi shield + ultrasonic sensor. I found switching from pins 13(trig) and 11(echo) to 8(trig) and 3(echo) fixed it.
See here: http://forum.arduino.cc/index.php?topic=201827.0

Reading sensor input with Pic32 and MPIDE

So I currently have a pic32 arduino. I'm pretty new to this stuff, so any tips would be appreciated.
I have a sensor that has 3 pins, 5VDC, ground, and sensor output. I connected the sensor output and ground header to the two pin slots at PORT0.
For some reason, the program always reads that the sensor is HIGH, even if the sensor is not connected.
If I connect the output to a breadboard with an LED, I can see the LED toggle on and off.
Here is my code:
const int sensor = 0; //sensor port
int sensorState = LOW;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(piezo, OUTPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
}
void loop(){
sensorState = digitalRead(sensor);
if(sensorState == HIGH)
alarm();
digitalWrite(ledPin, sensorState);
Serial.println(sensorState);
}
You may have the internal pull-up resistor enabled, so when nothing is connected, it will read high.
Also, these two statements are contradictory:
For some reason, the program always reads that the sensor is HIGH, even if the sensor is not connected.
If I connect the output to a breadboard with an LED, I can see the LED toggle on and off.
So the program always reads high but the LED toggles on or off? Which one is it?
If you manually pull the pin to ground, does your program react the way it is supposed to? If it does, then you should take a look at your sensor circuit.
Your sensor circuit sounds weird - you say
I have a sensor that has 3 pins, 5VDC, ground, and sensor output. I connected the sensor output and ground header to the two pin slots at PORT0
So the sensor output and ground are connected to pin zero? 5v should go to 5v, ground should go to ground, the sensor output should go to pin zero.

Arduino ultrasonic initialisation issue

Hardware:
Arduino MEGA 2560
2 x MaxBotix MaxSonar-EZ0
Software (relating to Ultrasonics, by no means the entire program):
void setup() {
Serial.begin(9600);
//Ultrasonic Left
pinMode(26, OUTPUT);
pinMode(2, INPUT);
digitalWrite(26, LOW);
//Ultrasonic Right
pinMode(27, OUTPUT);
pinMode(3, INPUT);
digitalWrite(27, LOW);
}
void readSonar() {
digitalWrite(26, HIGH);
delayMicroseconds(25);
digitalWrite(26, LOW);
data[0] = pulseIn(2, HIGH);
digitalWrite(27, HIGH);
delayMicroseconds(25);
digitalWrite(27, LOW);
data[1] = pulseIn(3, HIGH);
return data;
}
Problem:
When the Arduino is first booted, the readings from the two Ultrasonic sensors are not being updated. They are reporting as non-zero values, typically in the range of 500 - 1500. They fluctuate a little (most likely due to noise in the power supply), but tend to stay around the value that they initialise to.
As per the data sheet for these sensors, there are no obstacles within 14 inches of the sensors during the initialisation stage.
By simply disconnecting and reconnecting the cable going to the sensors (from the back of the sensor, not directly to the Arduino inputs), I am able to receive accurate readings from the sensors immediately.
Has anyone had this problem before? My setup() function looks 'normal' from the examples that I have seen. In order to fix this problem, I have connected a switch for the active lines of both sensors. This way the Arduino can boot and then I can give the sensors power. This seems like a botched workaround to me, and I would like a hard-coded software solution, if anyone is able to provide one!
If you look at the characteristics of the sensor it looks clear that you need to start them with the Rx at 0. Look at this link. This is most probably the reason why you have to disconnect the sensor after you start the Arduino to get it working. You also need to make sure that you have pullup resistors connected to avoid unreliability of the readings.

Resources