Small air blower (12V DC motor) only buzzing - arduino

I'm trying to get my DC Brushless fan (an air blower like this one: https://iprototype.nl/products/components/overige/blower-squirrel-cage ) working.
This is my set-up: (note that the DC motor in the image is my fan)
And this is my code (nothing fancy):
int motorPin = 9;
void setup() {
Serial.begin(9600);
pinMode(motorPin, OUTPUT);
}
void loop() {
for(int i=0; i < 255; i++) {
analogWrite(motorPin, i);
Serial.println(analogRead(motorPin));
delay(5);
}
}
The only thing my air blower is doing is BUZZING. A little "peeeeep" coming out of it, so there is a connection but it doesn't seem to work for some reason.
My battery i'm using is a normal Duracell 9V battery and when I hold the cables of my air blower against the + and - of my battery it works pretty well, so the voltage should be enough.
Would anyone know a solution for this?

First off I would be careful posting this here. There are a TON of trolls that will push you off Stack Overflow because this is an Engineering question.
That said:
First thing I noticed that is wrong.
You are using analogWrite(motorPin, i); but you clearly have it plugged into the digital pins on the Arduino. The pins that are marked A0-A5 are your analog pins.
What you want to use is digitalWrite(pin,value)
Arduino Documentation
Second, have you tested this with a multimeter?
I would be concerned with how much current is actually getting to your blower and if it's enough to run it. This really depends on how it is wired. I would suggest using an H-Bridge for anything motor related. You can find them REALLY cheap on sparkfun. I use one from adafruit. You can see an example of it working and how it's wired at http://anthonyrussell.info/postpage.php?name=65 If you could attach an actual photo of your setup that might be a little more useful

Related

Trouble speeding up arduino

I'm trying to speed up my Arduino code by direct writing to registers. I wrote a short test script, but it doesn't seem to do much. If I use the 'digitalWrite()' function I can see an output on the oscilloscope, but using this code it just stays 0.
I used this link as a reference. I can't quite grasp what I missed.
byte *outputRegister;
byte bitMask;
void setup() {
pinMode(8,OUTPUT);
outputRegister = portOutputRegister(8);
bitMask = digitalPinToBitMask(8);
}
void loop() {
*outputRegister |= bitMask;
delay(1);
*outputRegister &= ~bitMask;
delay(1);
}
EDIT: The portOutRegister should return the port where the output pins are set. The digitalPinToBitmask function returns a bitmask (something like 0b00000001 for the first pin on the respective port).
With some further testing, I concluded that the digitalWrite function doesn't seem to actually change the values in these registers, which does nothing more than confuse me.
Arduino, if its Model = Uno, then it is ATmega-328 AVR, the best way to solve critical timing issues and achieve better execution times and code optimizations you should program via direct register modifications. That being said, use AVR-GCC, include and then do bit twiddling. Your code is not readable and hard to understand.
IMO you should either write in C++ inside Arduino IDE >> slower but easier option, or
start programming outside IDE inC and directly the AVR, >> orders of magnitude performance increase. Get to know the AVR Freaks Forum.

How to do Led blink with each port, using stm32 (stm32f103c8t6) boards and Adruino

I am completely new to this and willing to do a simple task using stm32f103c8t6 board, which is "led blink".
Using ArduinoIDE and a simple circuit as shown in the picture, everything goes fine on port PC13. but as soon as I try other ports, it doesn't work.
My aim is to be able to toggle the led status using ports PA0 to PA5.
Here is my code:
void setup() {
// initialize the digital pin as an output.
pinMode(PC13, OUTPUT);
}
void loop() {
digitalWrite(PC13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(PC13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
I change PC13 to PA0, and rewire the board, but no luck :(
How can I solve this issue.
Any kind of help is highly appreciated.
You are using an external LED right (it's a bit difficult to tell for sure in your photo)? The "blue pill"'s internal LED is tied to PC13 only. If you are using an external LED and the program with PC13 works, then there should not be any issue with PA0 to PA5. The only thing I can think of currently is that somehow your program is not being flashed correctly so it's still running the old code.
To test this theory, start with the working PC13 program and then modify the delay time to 2 secs or whatever. Then you can be sure that the new program is downloaded correctly.
Sorry for the stupid question. My problem was that I had a broken wire,and when I changed it, everything was working fine.

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.

Olimex EKG-EMG arduino shield (linux monitor)

Recently I have started using an EKG/EMG arduino's shield from Olimex: EKG/EMG Shield
The documentation have references for Electric Guru software only, but this software is closed source and it doesn't works in Linux.
I searched in internet but I have not success results.
My question is: is there another monitor software or any example for plot the captured signals by the electrodes?
not as I would know.
whowever, looking at the source code that is turning at the arduino microcontroller the protocol is fairly simple. I mean this one: https://www.olimex.com/Products/Duino/Shields/SHIELD-EKG-EMG/resources/ShieldEkgEmgDemo.zip
if i remember well, it sends out the packets: the rotating packet counter [count], and array of measurements [data] separated by 0xa5 0x5a bytes.
struct Olimexino328_packet
{
uint8_t sync0; // = 0xa5
uint8_t sync1; // = 0x5a
uint8_t version; // = 2 (packet version)
uint8_t count; // packet counter. Increases by 1 each packet.
uint16_t data[6]; // 10-bit sample (= 0 - 1023) in big endian (Motorola) format.
uint8_t switches; // State of PD5 to PD2, in bits 3 to 0.
};
some time ago, I have written a small python script for interfacing that (which is not finished yet), where you could do whatever you wish with the data - plotting, cool calculations and machine learning, etc. If you are interested, I could search for, and send you the source code... best after march 15.
however so far for some reason it starts receiving the data only after starting the Electric Guru once.
cheers
Maybe this helps you a bit, im also trying to build an open source component
http://bakerdh.wordpress.com/2013/01/31/a-first-look-at-the-olimex-eeg-smt/
I am working on a Python package to capture data from the Olimex EKG/EMG shield.
https://pypi.python.org/pypi
I am currently working towards a pre-alpha release.
Update:
I just pushed up an alpha version of the package I mentioned before to PyPI.
https://pypi.python.org/pypi/olimex-ekg-emg/0.1.0
I have a github repo that contains a Processing 3 visualizer that might be helpful. Processing 3 is very similar to the Arduino IDE.
https://github.com/fractalbass/ekg_field_monitor/tree/master/processing/ECG_Display
I also have a blog post that goes into some detail about what is going on in that sample program...
https://pragmaticiot.wordpress.com/2016/04/13/i-got-rhythm/
In the end, all you really need to do with the shield is just read the values on pins A0-A5. They will contain values you can graph to get the waveforms.
Good Luck
Miles Porter
Mporter#paintedharmony.com
Arduino IDE now has inbuilt Serial Plotter under Tools menu. Olimex provides a good document for hooking everything up and this is their code:
const int analogInPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(analogInPin);
Serial.println(sensorValue);
}

Two port receive using software serial on Arduino

i am having trouble getting data from two sensors using two software serial ports with an arduino board. I noticed a similar question might have been asked before but the answers suggest it can't be done and I know fully well it can based on the example here (http://arduino.cc/en/Tutorial/TwoPortReceive)!
I am using an arduino ethernet. The devices I am trying to get data from include a GPS and an IMU both from sparkfun.
I can get data from either devices using just on software serial port but as soon as I add the second software serial port, neither ports will work. I can't use the hardware serial port because that is being used byt another device.
My code is exactly similar to the example:
#include <SoftwareSerial.h>
SoftwareSerial portOne(7,8);
SoftwareSerial portTwo(5,6);
void setup()
{
Serial.begin(9600);
portOne.begin(9600);
portTwo.begin(9600);
}
void loop()
{
portOne.listen();
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
}
delay(500);
portTwo.listen();
while (portTwo.available() > 0) {
char inByte = portTwo.read();
Serial.write(inByte);
}
Serial.println();
}
Anyone with any ideas?
This code will not work, or will work poorly if it works at all. SoftwareSerial only has one internal buffer. Yes, you can have multiple SoftwareSerial objects in existence, but only one of them controls the internal buffer. When any RX pin gets asserted, that generates an interrupt, but only the listen()ing RX pin gets checked for a start bit.
What's really needed is the ability to check on multiple pins when an interrupt comes along from the start bit. Then you'd have to set up pointers to the appropriate data structures. It would be complicated, but possible.
Or maybe just give up on interrupt-driven reception, and spin on checking both/all of the RX pins, and start the receive based on the pin you see. Be forwarned that this code has much hair, and you WILL need an oscilloscope to make it work.
I'm having a similar problem, which is why I found your sensor. After talking it over with my co-workers, we've decided to read our sensors in rotating order. Our sensors report the current state of the sensor, and not specific events, so it's okay if we lose some reports. So we'll read from port 1, then read from port 2, then port 1, etc. Our sensors spit out lines of text, so we know when to switch to the next sensor.
The referenced example only actively listens to one port at a time. The recommended solution would be to upgrade to an Arduino Mega (https://www.sparkfun.com/products/11061) which has 4 hardware serial ports.
In order to simultaneously support two software serial ports is going to require a lot of the CPU resources. It also be a difficult design and excessive programming time far outweighing the cost of $58 + shipping.
Looking at you code again it occurs to me that you are immediately checking for characters after your portOne.listen command. At 9600 baud it will take approximately 1ms for the first character to arrive, your while test will have been completed and the portTwo.listen command executed long before the first character arrives.
For testing purposes try adding a 1-2 ms delay after the portOne.listen command and see if you get a character.
As an example (untested and note, if port one is sending characters with no intercharacter gaps, the first while will never fail, preventing reading portTwo characters):
void loop()
{
portOne.listen();
delay(2);
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
delay(1);
}
portTwo.listen();
delay(2);
while (portTwo.available() > 0) {
char inByte = portTwo.read();
Serial.write(inByte);
delay(1);
}
Serial.println();
}
Don't use while ......
Use:
{ portOne.listen();
if (PortOne.available() ) {
ricevo = myPort1.read(); }
// delay(2); // ridiculos waiting time
// delay(1); // extra ridiculos waiting time
Than 500 ms is a too big time for switching, no time.....

Resources