# Relay shield for arduino problems

Joined Jan 15, 2015
5,512
Would adding "LOW" statement to the next else if do?

Ex:

If(t =='F') {
DigitalWrite (13, HIGH);
}
Else if(t == 'B'){
DigitalWrite(13, LOW);
DigitalWrite(12, HIGH);
}
Tomorrow I'll play around with it. Remember I told you I am not a programmer type, I just play around with the stuff because it keeps my brain doing something in old age. I do know when we tell a pin to go High it will remain there till we tell it different. Something does come to mind. Usually with motors or a model car we have a standard motor FWD and REV and another motor for steering Left and Right. Normally a button is held and the motor runs as long as the button is held. Crudely put but close to what's happening. We can toss in a throttle for motor speed and get more complex but crude and simple is good for now.

Using communications like we are is a different animal. I am sure someone good with this stuff could just bang the code out but me? I need to think about it.

Ron

#### Killerbee65

Joined May 15, 2017
222
Tomorrow I'll play around with it. Remember I told you I am not a programmer type, I just play around with the stuff because it keeps my brain doing something in old age. I do know when we tell a pin to go High it will remain there till we tell it different. Something does come to mind. Usually with motors or a model car we have a standard motor FWD and REV and another motor for steering Left and Right. Normally a button is held and the motor runs as long as the button is held. Crudely put but close to what's happening. We can toss in a throttle for motor speed and get more complex but crude and simple is good for now.

Using communications like we are is a different animal. I am sure someone good with this stuff could just bang the code out but me? I need to think about it.

Ron
Thanks! I'll try to do some research on that!

#### Killerbee65

Joined May 15, 2017
222
There's been a development. I found a code online that cuts this project of mine down to maybe a day. I'll post the video and website. Basically the ultimate goal was to make the motors be controlled by a ps4 controller. I know I didn't mention it earlier but I wanted to first figure out how to make my relay shield work, but as most of you know that idea was scrapped. So now, I have my motors wired to the h-bridge and the h-bridge to my Arduino and the shields. I found the perfect code online for this and the only error I'm getting is as follows:

Code:
//Source Code
#include <PS4BT.h>
#include <usbhub.h>

// Satisfy the IDE, which needs to see the include statement in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
int IN1 = 3;       //control pin for first motor
int IN2 = 4;       //control pin for first motor
int IN3 = 5;        //control pin for second motor
int IN4 = 6;        //control pin for second motor
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so

/* You can create the instance of the PS4BT class in two ways */
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode
PS4BT PS4(&Btd, PAIR);

// After that you can simply create the instance like so and then press the PS button on the device
//PS4BT PS4(&Btd);

bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;

void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
Serial.begin(115200);
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); // Halt
}
Serial.print(F("\r\nPS4 Bluetooth Library Started"));

}
void loop() {

if (PS4.connected()) {
//  if (PS4.getAnalogHat(LeftHatX) > 137 || PS4.getAnalogHat(LeftHatX) < 117 || PS4.getAnalogHat(LeftHatY) > 137 || PS4.getAnalogHat(LeftHatY) < 117 || PS4.getAnalogHat(RightHatX) > 137 || PS4.getAnalogHat(RightHatX) < 117 || PS4.getAnalogHat(RightHatY) > 137 || PS4.getAnalogHat(RightHatY) < 117) {
if(PS4.getAnalogHat(LeftHatX)<10)
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
Serial.print("\nHatX: 50 ");
}
else if(PS4.getAnalogHat(LeftHatX)>240)
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);

Serial.print("\nHatX: 200 ");
}
else if(PS4.getAnalogHat(LeftHatY) < 20)
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);

Serial.print("\nHatY: 50 ");
}
else if(PS4.getAnalogHat(LeftHatY) > 200)
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
Serial.print("\nHatY: 200 ");
}
else {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
Serial.print("\nrotate the joystick ");

}

}
}

ERROR:
ps4_car:2:10: fatal error: PS4BT.h: No such file or directory

#include <PS4BT.h>

^~~~~~~~~

compilation terminated.

exit status 1
PS4BT.h: No such file or directory

Website:
https://maker.pro/arduino/projects/how-to-control-an-arduino-robot-with-a-ps4-bluetooth-controller

Video:

#### KeepItSimpleStupid

Joined Mar 4, 2014
4,106

#### Killerbee65

Joined May 15, 2017
222
I've actually seen that before but I don't know how to use it to read it. I only know how to upload a library using a zip file and that's about it

Joined Jan 15, 2015
5,512
OK you may want to start by reading this. You can take the code and copy and paste it into notepad (in most instances). Then in your libraries folder create a new folder naming it whatever the file is (my_library.h). That done the library should show up in your libraries in the IDE. Originally this was going to be a simple project involving a few relays and controlled using a comm port to communicate with Arduino. Bluetooth will require a USB Host Shield and a USB Dongle. This is why when you see:
#include <PS4BT.h>
#include <usbhub.h>
There is a library for the PS4 and also the USB hub.

You never mentioned anything wireless till now. Best of luck and if you get or have the few remaining pieces of hardware it should work. I really don't see where I can be of any further help to you.

Ron

#### Killerbee65

Joined May 15, 2017
222
OK you may want to start by reading this. You can take the code and copy and paste it into notepad (in most instances). Then in your libraries folder create a new folder naming it whatever the file is (my_library.h). That done the library should show up in your libraries in the IDE. Originally this was going to be a simple project involving a few relays and controlled using a comm port to communicate with Arduino. Bluetooth will require a USB Host Shield and a USB Dongle. This is why when you see:
#include <PS4BT.h>
#include <usbhub.h>
There is a library for the PS4 and also the USB hub.

You never mentioned anything wireless till now. Best of luck and if you get or have the few remaining pieces of hardware it should work. I really don't see where I can be of any further help to you.

Ron
I have the USB host and a dongle. Thank you for your help though you are greatly appreciated!