Friday, 29 July 2016

hardware - Can I use the analog pins on the Arduino for my project as digital?


I am new to using Arduino, and I have an Arduino Uno. For the projects I've done, I've only used the digital pins.


I am building a small vehicle that uses stepper motors. I have run out of pins to control the motors for this vehicle. What are the analog pins for? Is it possible for me to use analog pins to control the rest of the step motors which I connect to the Arduino, or do I have to buy a bigger Arduino than Arduino Uno to control this contraption?



Answer



Yes, the analog pins on the Arduino can be used as digital outputs.



This is documented in the Arduino input pins documentation, in the Pin Mapping section:



Pin mapping
The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);



No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...