Good! I have a circuit in which I connect an Arduino to an NFC Shield and it is to a protoboard. My goal is to activate an electric lock that works with 10-24V AC and DC, for this I have placed a transistor 2N2222 and a resistance of 330 Ohms. The problem that I have esque when I connect the plate protoboard to the lock, the LED is turned on, but the lock is immovable.
This is the scheme on which I have based myself to assemble everything.
And this is the image of how I have it armed:
And finally I have the code that I am using:
#include <PN532.h>
#include <SPI.h>
/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
/*if you the version of NFC Shield from SeeedStudio is v2.0.*/
#define PN532_CS 10
PN532 nfc(PN532_CS);
#define NFC_DEMO_DEBUG 1
const int control = 7 ;
const int speed = 200;
void setup(void) {
pinMode(control, OUTPUT) ;}
void loop(void) {
digitalWrite(control, HIGH);
delay(2000);
digitalWrite(control, LOW);
delay(1000);
}
it doesn't happends because your supply in +5v (from USB) and can not change state of +24v equipment.
you should connect a +12v supply to the collector of your transistor.
do like this :
Related
I'm using a ESP32 30 pin board, MAX30100 pulse sensor for my project.
I can interface this sensor to ESP32's different i2c pins i.e. not default pins(21,22).
But I don't know how to read data from the MAX30100 if it connected to different pins - (Let's say 32, 33)
This is the program I used for default i2c pins to read data from MAX30100
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define REPORTING_PERIOD_MS 1000
char auth[] = "*******************"; // You should get Auth Token in the Blynk App.
// Connections : SCL PIN - D1 , SDA PIN - D2 , INT PIN - D0
PulseOximeter pox;
float BPM, SpO2;
uint32_t tsLastReport = 0;
void onBeatDetected()
{
Serial.println("Beat Detected!");
}
void setup()
{
Serial.begin(115200);
pinMode(19, OUTPUT);
Blynk.begin(auth,"************", "**********");
Serial.print("Initializing Pulse Oximeter..");
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
}
else
{
Serial.println("SUCCESS");
pox.setOnBeatDetectedCallback(onBeatDetected);
}
// The default current for the IR LED is 50mA and it could be changed by uncommenting the following line.
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
}
void loop()
{
pox.update();
Blynk.run();
BPM = pox.getHeartRate();
SpO2 = pox.getSpO2();
if (millis() - tsLastReport > REPORTING_PERIOD_MS)
{
Serial.print("Heart rate:");
Serial.print(BPM);
Serial.print(" bpm / SpO2:");
Serial.print(SpO2);
Serial.println(" %");
Blynk.virtualWrite(V3, BPM);
Blynk.virtualWrite(V4, SpO2);
tsLastReport = millis();
}
}
How do I interface MAX30100 to other pins? What should be the instructions?
PulseOximeter pox;
What does this instruction mean?
You should change direction in library:
Link to library file in github
Line 29: change that for
Wire.begin(SDA_PIN, SCL_PIN);
Where SDA_PIN and SCL_PIN are defines of your own routing.
NOTE: if you change the library you will need always to use that pins for all of your developments so maybe is better if you import that library locally or even better if you change library so if you don't pass any pin at argument it default normally I2C pins but, if defined use the defined ones.
I am trying to get a temperature reading using a single dsb1820 temperature sensor attached to an esp32 micro controller. The sensor is attached to GPIO-4 of the esp32. I intend to send the temperature reading to a cloud.
The problem i am facing is that the temperature reading always gives the value -127.
I read somewhere online that when the dsb1820 returns -127 it means that the sensor is not connected.
Am I using the wrong pin to connect the sensor?
#include "OneWire.h"
#include "DallasTemperature.h"
#include <WiFi.h>
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"
OneWire oneWire(4);
DallasTemperature tempSensor(&oneWire);
void setup(void)
{
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
tempSensor.begin();
}
void loop(void)
{
tempSensor.requestTemperaturesByIndex(0);
Serial.print("Temperature: ");
Serial.print(tempSensor.getTempCByIndex(0));
Serial.println(" C");
delay(2000);
}
Check your cables and:
const int oneWireBus = 32; // on pin 32 /GPIO7/D0 on pcb (a 4.7K resistor is necessary)
OneWire oneWire(oneWireBus);
and it should be the middle pin of the sensor (see my graphic)
EDIT
The DevKit has no pin 4 either you use GPIO4 (4 on the pcb) which is in Arduino 24 BUT
The following strapping pins: 0, 2, 4, 5 (HIGH during boot), 12 (LOW
during boot) and 15 (HIGH during boot) are used to put the ESP32 into
bootloader or flashing mode. Don't connect peripherals to those pins!
If you do, you may have trouble trying to upload code, flash or reset
the board.
Connect to 32 (GPIO7 or D0 on the pcb) as this is safe for testing
If you have that wrong or no/wrong resistor it will give you -127 (or you killed the sensor/it was DOA).
I have an ATTiny85 connected to an NRF24L01+ module using this wiring diagram: diagram. The ATTiny85 periodically goes in and out of sleep to send some value to a receiver, an Arduino Uno. If the ATTiny is running off the Arduino power supply (3.3v), everything works correctly. When I run the ATTiny off of a separate CR2032 coin cell that delivers around 3v, the Arduino never receives any data. I have a status LED hooked up to the ATTiny to ensure that the ATTiny is waking correctly, which it is. Here's the code for both:
EDIT:
Connecting it to an external 3.3v not from the Uno makes everything work - why wouldn't the coin cell's voltage work? I think everything is rated below 2.8v, the CR2032 minimum.
ATTiny Code
#include <avr/sleep.h>
#include <avr/interrupt.h>
// Routines to set and claer bits (used in the sleep code)
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define CE_PIN 3
#define CSN_PIN 3 //Since we are using 3 pin configuration we will use same pin for both CE and CSN
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte address[11] = "SimpleNode";
unsigned long payload = 0;
void setup() {
radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openWritingPipe(address); // Write to device address 'SimpleNode'
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(1000);
setup_watchdog(6);
}
volatile int watchdog_counter = 0;
ISR(WDT_vect) {
watchdog_counter++;
}
void loop()
{
sleep_mode(); //Go to sleep!
if(watchdog_counter >= 5)
{
digitalWrite(4, HIGH);
watchdog_counter = 0;
payload = 123456;
radio.write( &payload, sizeof(unsigned long) ); //Send data to 'Receiver' ever second
delay(1000);
digitalWrite(4, LOW);
}
}
//Sleep ATTiny85
void system_sleep() {
cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System actually sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON
}
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {
byte bb;
int ww;
if (ii > 9 ) ii=9;
bb=ii & 7;
if (ii > 7) bb|= (1<<5);
bb|= (1<<WDCE);
ww=bb;
MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
}
Receiver Code
#define CE_PIN 7
#define CSN_PIN 8
#include <SPI.h>
#include "RF24.h"
RF24 radio(CE_PIN, CSN_PIN);
byte address[11] = "SimpleNode";
unsigned long payload = 0;
void setup() {
while (!Serial);
Serial.begin(115200);
radio.begin(); // Start up the radio
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(15,15); // Max delay between retries & number of retries
radio.openReadingPipe(1, address); // Write to device address 'SimpleNode'
radio.startListening();
Serial.println("Did Setup");
}
void loop(void){
if (radio.available()) {
radio.read( &payload, sizeof(unsigned long) );
if(payload != 0){
Serial.print("Got Payload ");
Serial.println(payload);
}
}
}
Is the problem here that the ATTiny and Uno need to be turned on at the same time to establish a connection, or is it something to do with the battery, or something else entirely? Any help would be appreciated.
I'm experiencing the same problem when running Arduino Nano from a battery.
Nano has a 3.3V pin that I'm using for powering the NRF24L01+ module.
When the voltage from my battery-pack drops under 3.3V, the 3.3V pin voltage also drops. After few minutes, the RF module is not sending any messages.
I fixed the problem temporarily by routing the battery through a 12V step-up regulator that I bought earlier for a different project. These 12V then go to the "UN" pin on Nano which accepts 6-20V. This setup works nicely but is definitely not optimal.
Therefore I'm planning to use a 3.3V step-up regulator such as Pololu 3.3V Step-Up Voltage Regulator U1V11F3 which, according to the supplier, can efficiently generate 3.3V from input voltages as low as 0.5V.
I think this might be helpful to your project as well.
I wrote a program that can capture moisture through a DHT11 sensor connected to an Arduino Uno. The captured value will be sent to an Android application using a Bluetooth HC-06 module. Everything works fine except that the latter (HC-06) does not send the captured moisture.
Can someone help me and thank you
The code is as follows:
#include <SoftwareSerial.h>
/* to communicate with the Bluetooth module's TXD pin */
#define BT_SERIAL_TX 10
/* to communicate with the Bluetooth module's RXD pin */
#define BT_SERIAL_RX 11
/* Initialise the software serial port */
SoftwareSerial BluetoothSerial(BT_SERIAL_RX, BT_SERIAL_TX);
// DHT-11 Configuration
#include <DHT.h> // lightweight DHT sensor library
#define DHTTYPE DHT11 // DHT 11
#define TEMPTYPE 0 // Use 0 for Celsius, 1 for Fahrenheit
#define DHTPIN 2
DHT dht(DHTPIN, DHTTYPE); // Define Temp Sensor
void setup() {
BluetoothSerial.begin(115200); // Initialise BlueTooth
Serial.begin(9600);
//delay(1000);
dht.begin(); // Initialize DHT Teperature Sensor
BluetoothSerial.print("Starting ...");
}
void loop() {
// Take readings
float h = dht.readHumidity(); // Read humidity
BluetoothSerial.println(h);
delay(500);
}
The master board is a Arduino Uno and the slave is a Arduino Yun. I have them both wired up using A4 & A5 of one board to attach to the A4 & A5 pin on the other. They are both powered separately but share the same ground like the diagram below.
The code for both master and slave are below. If the slave board is not powered the master knows it can not talk to the slave and won't print out Loop until the slave is powered. This suggests that the master knows of the slave.
However the slave never receives this signal from the master. receiveEvent is never called.
I am doing this as I have ran out of pins on the master and want the slave to control a LCD display that takes up several pins as I'm sure you all know.
Any help would be great, thanks.
Master
#include <Wire.h>
#define SLAVE_ADDRESS 0x9
void setup() {
Serial.begin(9600);
Wire.begin();
delay(1000);
}
void loop() {
Wire.beginTransmission(SLAVE_ADDRESS);
Wire.write('T');
Wire.endTransmission();
Serial.println("Loop");
delay(1000);
}
Slave
#include <Wire.h>
#define SLAVE_ADDRESS 0x9
void setup() {
Serial.begin(9600);
delay(1000);
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveEvent);
Serial.println("Setup");
}
void loop() {
// Serial.println("Loop");
}
void receiveEvent(int howMany){
Serial.println("Receive event");
while (Wire.available() > 0)
{
char c = Wire.read();
Serial.println(c);
}
}
Maybe you should think about the wiring.
Your Yun is using a different layout see: http://forum.arduino.cc/index.php?topic=191974.0
If the UNO is a R3 layout you can use the pins above AREF as far as I know. Check the exact pin-out of your Arduino(s).